package com.demo.enums;

import com.demo.common.exceptions.ServiceException;
import lombok.Getter;

import java.util.Arrays;

/**
 * 用户状态枚举
 */
@Getter
public enum SysUserStatusEnum {

    NORMAL(0,"正常"),
    FREEZE(1,"冻结");

    SysUserStatusEnum(int value,String label){
        this.value=value;
        this.label=label;
    }

    /**
     * 状态转名称
     * @param value
     * @return
     */
    public static String of(Integer value){
        SysUserStatusEnum statusEnum = Arrays.stream(SysUserStatusEnum.values()).filter(it -> it.getValue().equals(value)).findAny().orElseThrow(() -> new ServiceException("未找到对应状态枚举"));
        return statusEnum.getLabel();
    }

    private Integer value;

    private String label;
}
